<!-- 工单详情 》 工单底部 -->

<template>
  <div v-if="canDeal">
    <BtnPrimary v-for="config in configList" :key="config.method" :title="config.operate" @click="openDeal(config)" />
  </div>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'RepairFooter',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [
    CORE.mixWeb(),
    CORE.mixWeb('deal', 'deal_'),
  ],

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 配置列表
     */
    configList() {
      const { MAP, one } = this
      return MAP[one.status] || []
    },

    /**
     * 能否处理
     */
    canDeal() {
      if (CORE.isEmpty(this.configList)) return false
      return this.one.resolverUserId === CORE.USER.uaaUserId
    },
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 打开处理弹窗
     */
    openDeal(config) {
      const { one, $root: { repair_assign_selectDict: assign } } = this

      const obj = {
        ...config,
        remark: `${config.operate}意见`,
        workOrderId: one.id,
      }

      if (config.method === 'forward') {
        const [, organId, uaaUserId, name, phone] = assign.find(item => item[0] === one.orderSubTypeId) || []
        Object.assign(obj, {
          assignUserId: uaaUserId,
          assignUserName: name,
          assignUserPhone: phone,
          user: { uaaUserId, name, phone, organId: [organId] }, // 指派人
        })
      }

      this.deal_MAP.tipEdit = obj.operate

      this.deal_openEdit(obj)
    },
  },
}
</script>
